<?php

require_once dirname(__FILE__) . '/model/service/UserAgentService.php';
require_once dirname(__FILE__) . '/model/service/WebTrafficService.php';
require_once dirname(__FILE__) . '/model/domain/Report.php';
require_once dirname(__FILE__) . '/model/domain/HttpRequest.php';
require_once dirname(__FILE__) . '/model/util/Assert.php';
	
	// Create the analyzer - HTTP request, whether in strict mode or not, if we should collect data
	$analyzer = new WebTrafficService(new HttpRequest(), true, true);
	$service = new UserAgentService();
	$skip_bot_check = false;
	
	// Simple check if we have analyzed this ua. The trafficservice sets this cookie	
	if ( Assert::notEmptyOrWhitespace($_COOKIE['trafficanalyzer']) && $_COOKIE['trafficanalyzer'] == Report::HUMAN ) {
		$skip_bot_check = true;	
	} 
	
	$report = $analyzer->analyze_traffic($skip_bot_check);
	
	// Let's determine what to do with the user agent
	// If it's blacklisted
	if ( $report->is_blacklisted ) {
		echo "<h1>You're not allowed here</h1>";
	}
	
	// If it's a human and no hacker
	if ( $report->type_of_agent == Report::HUMAN && $report->exploit == false ) {
		echo "<h1>I'm a friendly human</h1>";
	}
	
	// If it's a skiddie
	if ( $report->exploit ) {
		echo "<h1>Exploit detected</h1>";
	}
	
	// If it's spam bot
	if ( $report->type_of_agent == Report::BOT && $report->spam ) {
		echo "<h1>I'm spammy!</h1>";
		// redirect to competition :D
		//$modx->sendRedirect('http://www.example.com', 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
	}
	

?>